<?php
/* ----------------------------------------------------------
--               JacoCMS by Jaco Ruit                      --
-------------------------------------------------------------
--     JacoCMS is Open Source and is lincenced under       --
--             GNU General Public Licence v3               --
--          http://www.gnu.org/copyleft/gpl.html           --
-------------------------------------------------------------
--       Please don't remove any text from the footers.    --
-------------------------------------------------------------
-- Credits:   * Jaco Ruit          ~     Scripts,MySQL     --     
-----------------------------------------------------------*/

#important includes
include 'includes/config.php';
include 'includes/database.class.php'; 

#create database connection
$database = new Database();
$database->connect();

#finish includes
include 'includes/core.class.php';
include 'includes/analytics.class.php';
include 'includes/settings.class.php';
include 'includes/page.class.php';
include 'includes/video.class.php';
include 'includes/article.class.php';

#vars, classes
$page = new Page();
$article = new Article();
$video = new Video();
$analytics = new Analytics();
$settings = new Settings();
$core = new Core();
$searchid = null;

#load style
$stylepath = $settings->loadStyle();
include ("style/" . $stylepath . "/styleinfo.php");

#analytics
$analytics->logVisitor();

#settings
if ($settings->videoGalleryEnabled())
{
	$custom = $page->getMenuCode();
	$custom .= '<li><a href="videogallery">Video Gallery</a></li>';
}
else
{
	$custom = $page->getMenuCode();
}

#get and filter extern vars 
if (isset($_GET['pid']))
{
	$postpid = $core->filter($_GET['pid']);
}
if (isset($_GET['type']))
{
	$posttype = $core->filter($_GET['type']);
}

$pidinf = "";
$pidtype ="";

#check if they are valid
if ($posttype == 'v')
{
	if($video->checkIfExists($postpid) == false)
	{
		header ("Location: Invalid Varserror");
	}
	else if ($video->checkIfExists($postpid) == true)
	{
		$pidinf = $video->getByID($postpid);
		$pidtype = "Video";
	}
	else
	{
		header ("Location: Invalid Varserror");
	}
}
else if ($posttype == 'a')
{
	if($article->checkIfExists($postpid) == false)
	{
		header ("Location: Invalid Varserror");
	}
	else if ($article->checkIfExists($postpid) == true)
	{	
		$pidinf = $article->getByID($postpid);
		$pidtype = "Article";
	}
	else
	{
		header ("Location: Invalid Varserror");
	}
}
else
{
	header ("Location: Invalid Varserror");
}

#yay, they're valid.

#put this javascript for maxlength of textarea + meta tag in head using seoheader.tpl
$javascript = '<script type="text/javascript">
function checkMaxLength(obj){
var maxLength=obj.getAttribute? parseInt(obj.getAttribute("MaxLength")) : ""
if (obj.getAttribute && obj.value.length>maxLength)
obj.value=obj.value.substring(0,maxLength)
}
</script>
<meta name="generator" content="JacoCMS" />';


$formcode = '<div id="form"><form name="newcomment" action="post' . $postpid . '-' . $posttype . '" method="post">
			<p>Name</p> <input type="text" name="poster" MaxLength="15" size="15" /><br />
			<p>Email Address</p> <input type="text" name="email" MaxLength="30" size="30" alt="Your email address will only be visible to the admin" /><p style="font-size:8px; color:gray">Your email address will only be visible to the admin.<br />
			<p>Comment</p> <textarea rows="10" cols="30" name="commenttext" MaxLength="250" onkeyup="return checkMaxLength(this)"></textarea> <br />
			<input type="submit" value="Post New Comment" /></form></div>';

			
			
#template
$smarty->assign("stylecss", $stylepath);
$smarty->assign("webname", $settings->getWebsiteName());
$smarty->assign("pagename", "Post New Comment");
$smarty->assign("articles", $formcode);
$smarty->assign("headertext", "Comment on " . $pidtype . ": " . $pidinf['title'] );
$smarty->assign("stylename", $stylename);
$smarty->assign("styleauthor", $author);
$smarty->assign("authorwebsite", $authorwebsite);
$smarty->assign("custom", $custom);
$smarty->assign("metatags", $javascript);
$smarty->display("seoheader.tpl");
$smarty->display("menu.tpl");
$smarty->display("index.tpl");
$smarty->display("footer.tpl");

?>